package com.lifeverse.entity.enums;

/**
 * 性能指标状态枚举
 */
public enum MetricStatus {
    
    /**
     * 正常
     */
    NORMAL("正常"),
    
    /**
     * 警告
     */
    WARNING("警告"),
    
    /**
     * 异常
     */
    ABNORMAL("异常"),
    
    /**
     * 临界
     */
    CRITICAL("临界"),
    
    /**
     * 未知
     */
    UNKNOWN("未知"),
    
    /**
     * 不可用
     */
    UNAVAILABLE("不可用");
    
    private final String description;
    
    MetricStatus(String description) {
        this.description = description;
    }
    
    public String getDescription() {
        return description;
    }
    
    /**
     * 判断是否为健康状态
     */
    public boolean isHealthy() {
        return this == NORMAL;
    }
    
    /**
     * 判断是否需要关注
     */
    public boolean needsAttention() {
        return this == WARNING || this == ABNORMAL || this == CRITICAL;
    }
    
    /**
     * 判断是否为严重状态
     */
    public boolean isSevere() {
        return this == CRITICAL || this == UNAVAILABLE;
    }
    
    /**
     * 获取状态的严重程度等级（1-5，5最严重）
     */
    public int getSeverityLevel() {
        switch (this) {
            case NORMAL:
                return 1;
            case WARNING:
                return 2;
            case ABNORMAL:
                return 3;
            case CRITICAL:
                return 4;
            case UNAVAILABLE:
                return 5;
            case UNKNOWN:
            default:
                return 3;
        }
    }
    
    /**
     * 根据严重程度获取状态
     */
    public static MetricStatus fromSeverityLevel(int level) {
        switch (level) {
            case 1:
                return NORMAL;
            case 2:
                return WARNING;
            case 3:
                return ABNORMAL;
            case 4:
                return CRITICAL;
            case 5:
                return UNAVAILABLE;
            default:
                return UNKNOWN;
        }
    }
}